package com.servlet.user;

import com.service.EmployeeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/user/changePassword")
public class ChangePasswordServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String oldpassword=req.getParameter("oldpassword");
        String newpassword=req.getParameter("newpassword");
        String id=(String) req.getSession().getAttribute("userName");

        EmployeeService employeeService=new EmployeeService();

        if(employeeService.changePassword(id,oldpassword,newpassword)){
            req.setAttribute("Message","修改成功！");
        }else{
            req.setAttribute("Message","旧密码错误，修改失败！");
        }
        req.getRequestDispatcher("userchangepassword.jsp").forward(req, resp);
    }
}
